package com.qf.ks.service.impl;

import com.qf.ks.constans.ResultCode;
import com.qf.ks.exception.AddDataException;
import com.qf.ks.mapper.CategoriesMapper;
import com.qf.ks.service.CategoriesService;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class CategoriesServiceImpl implements CategoriesService {
    private CategoriesMapper categoriesMapper;
    @Autowired
    public void setCategoriesMapper(CategoriesMapper categoriesMapper) {
        this.categoriesMapper = categoriesMapper;
    }

    @Override
    public void AddCategories(String categoryname) {
        if (categoryname==null){
            throw new AddDataException("分类为空", ResultCode.NULL_CATEGORIES);
        }
        if (categoriesMapper.SelectCategoriesByname(categoryname)!=null){
            throw new AddDataException("分类存在",ResultCode.NULL_CATEGORYNAME);
        }
        categoriesMapper.AddCategories(categoryname);
    }
}
